/*
 * @lc app=leetcode.cn id=200 lang=cpp
 *
 * [200] 岛屿数量
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    void bfs(vector<vector<char>> &grid, int row, int column)
    {
        if (row < grid.size() && row >= 0 && column >= 0 && column < grid[0].size())
        {
            if (grid[row][column] == '1')
            {
                grid[row][column] = '0';

                bfs(grid, row - 1, column);
                bfs(grid, row + 1, column);
                bfs(grid, row, column - 1);
                bfs(grid, row, column + 1);
            }
        }
    }
    int numIslands(vector<vector<char>> &grid)
    {
        int ans = 0;

        for (int i = 0; i < grid.size(); i++)
        {
            for (int j = 0; j < grid[0].size(); ++j)
            {
                if (grid[i][j] == '1')
                {
                    bfs(grid, i, j);
                    ans++;
                }
            }
        }

        return ans;
    }
};

// int main()
// {
//     vector<vector<char>> grid = {{'1', '0', '1', '1', '0', '1', '1'}};
//     cout << Solution().numIslands(grid) << endl;
//     return 0;
// }

// @lc code=end
